package com.cmnit.utils

import java.util.Date

object ModelUtils {
  /**
   * 获取车牌号
   *
   * @param vehicleplate 车牌号+颜色
   * @return 返回所有设备数量
   */
  def getVlpUDF(vehicleplate: String): String = {
    vehicleplate.split("_")(0)
  }

  /**
   * 获取车牌颜色
   *
   * @param vehicleplate 车牌号+颜色
   * @return 返回所有设备数量
   */
  def getVlpcUDF(vehicleplate: String): String = {
    vehicleplate.split("_")(1)
  }

  /**
   * 获取指定时间对象上一个小时的年月日时
   *
   * @param date 日期对象
   * @return
   */
  def getTime(date: Date): (String, String, String, String) = {
    val hour = DateUtil.getLastHour(date)
    val day = DateUtil.getLastHourOfDay(date)
    val month = DateUtil.getLastHourOfMonth(date)
    val year = DateUtil.getLastHourOfYear(date)
    (hour, day, month, year)
  }

  /**
   * 获取账期时间，若不指定时间则默认前一个小时
   *
   * @param year  年
   * @param month 月
   * @param day   日
   * @param hour  小时
   * @return
   */
  def getAcctDate(year: String, month: String, day: String, hour: String): (String, String, String, String) = {
    if (year != "" && month != "" && day != "" && hour != "") {
      (hour, day, month, year)
    } else {
      getTime(new Date)
    }
  }
}
